home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19950329-19950528 / 000357_news@columbia.edu_Wed May 10 20:53:55 1995.msg < prev    next >
Internet Message Format  |  2020-01-01  |  4KB

  1. Received: from apakabar.cc.columbia.edu by watsun.cc.columbia.edu with SMTP id AA11155
  2.   (5.65c+CU/IDA-1.4.4/HLK for <kermit.misc@watsun.cc.columbia.edu>); Wed, 10 May 1995 16:54:18 -0400
  3. Received: by apakabar.cc.columbia.edu id AA10093
  4.   (5.65c+CU/IDA-1.4.4/HLK for kermit.misc@watsun); Wed, 10 May 1995 16:54:14 -0400
  5. Path: news.columbia.edu!watsun.cc.columbia.edu!fdc
  6. From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
  7. Newsgroups: comp.protocols.kermit.misc
  8. Subject: XIF for MS-DOS Kermit
  9. Date: 10 May 1995 20:53:55 GMT
  10. Organization: Columbia University
  11. Lines: 107
  12. Message-Id: <3or953$9q8@apakabar.cc.columbia.edu>
  13. Nntp-Posting-Host: watsun.cc.columbia.edu
  14. Apparently-To: kermit.misc@watsun.cc.columbia.edu
  15.  
  16.  
  17. The MS-DOS Kermit script programming language has an IF command that looks
  18. like this:
  19.  
  20.   IF <condition> <command>
  21.  
  22. which executes the <command> if the <condition> is true.
  23.  
  24. The C-Kermit language has this too, but also has an "extended IF", or
  25. XIF, command:
  26.  
  27.   XIF <condition> { <commands> } [ ELSE { <other-commands> } ]
  28.  
  29. in which the <commands> are one or more commands separated (if more than
  30. one) by commas, and there is an optional ELSE part to be executed if the
  31. <condition> is not true.  This is handy for grouping commands together to
  32. be executed conditionally without resorting to lots of ugly GOTOs.
  33.  
  34. Here is a macro that you can use in MS-DOS Kermit to get the XIF effect.
  35. It is *almost* totally compatible with C-Kermit's XIF command, but not
  36. quite.  The difference is that, when using this macro, you must enclose
  37. the <condition> in curly braces, whereis in C-Kermit, you must *not*
  38. enclose the <condition> in curly braces.  Left as an exercise to the
  39. reader: eliminate this incompatibility :-)
  40.  
  41. ---(cut)---
  42. define XIF -
  43.   _assign _then\v(cmdlevel) \%2,-
  44.   if def \%3 if not eq "\%3" "ELSE" end 1 "\%3" should be "ELSE",-
  45.   if def \%4 _assign _else\v(cmdlevel) \%4,-
  46.   if \%1 do _then\v(cmdlevel),-
  47.   if def \%4 if NOT \%1 do _else\v(cmdlevel)
  48. ---(cut)---
  49.  
  50. Aside from the { <condition> } business, you should be able to use this macro
  51. exactly as you would use C-Kermit's XIF.  Here is a script to give it a
  52. workout:
  53.  
  54. ---(cut)---
  55. ec Testing XIF...
  56.  
  57. xif { = 1 1 } { echo THEN part works. }
  58. xif { = 1 0 } { echo This should not appear } else { echo ELSE part works. }
  59.  
  60. echo Multiple commands in THEN part... 
  61. xif { = 1 1 } { echo Line 1 of 3 OK, ec Line 2 of 3 OK, ec Line 3 of 3 OK }
  62.  
  63. echo Same thing, with line continuation...
  64. xif { = 1 1 } { -
  65.   echo Line 1 of 3 OK,-
  66.   echo Line 2 of 3 OK,-
  67.   echo Line 3 of 3 OK -
  68. }
  69.  
  70. echo Multiple commands in THEN and ELSE parts, THEN part true... 
  71. xif { = 1 1 } { -
  72.   echo THEN 1 of 3 OK,-
  73.   echo THEN 2 of 3 OK,-
  74.   echo THEN 3 of 3 OK -
  75. } else { -
  76.   echo ELSE 1 of 3 OK,-
  77.   echo ELSE 2 of 3 OK,-
  78.   echo ELSE 3 of 3 OK -
  79. }
  80.  
  81. echo Multiple commands in THEN and ELSE parts, THEN part false... 
  82. xif { = 1 0 } { -
  83.   echo THEN 1 of 3 OK,-
  84.   echo THEN 2 of 3 OK,-
  85.   echo THEN 3 of 3 OK -
  86. } else { -
  87.   echo ELSE 1 of 3 OK,-
  88.   echo ELSE 2 of 3 OK,-
  89.   echo ELSE 3 of 3 OK -
  90. }
  91.  
  92. echo Testing nested XIFs...
  93.  
  94. xif { = 1 1 } { -
  95.   xif { = 2 0 } { -
  96.      echo This should NOT appear -
  97.   } else { -
  98.      echo This SHOULD appear -
  99.   } - 
  100. } else { - 
  101.   echo This should NOT appear -
  102. }
  103.  
  104. echo And again...
  105. xif { = 1 0 } { -
  106.   echo This should NOT appear, -
  107.   xif { = 2 2 } { -
  108.      echo This should NOT appear -
  109.   } else { -
  110.      echo This should NOT appear -
  111.   } -
  112. } else { -
  113.   echo This SHOULD appear, -
  114.   xif { = 2 2 } { -
  115.      echo This SHOULD appear -
  116.   } else { -
  117.      echo This should NOT appear -
  118.   } -
  119. }
  120. ---(cut)---
  121.  
  122. - Frank